/**
 * fileName: IndexService.java
 *     Date: 2012-4-29
 **/
package com.stranger.index.service.impl;






import java.util.ArrayList;
import java.util.List;
import java.util.UUID;





import com.stranger.common.util.BeanUtils;
import com.stranger.index.bean.TeachersBean;
import com.stranger.index.dao.IndexDAO;
import com.stranger.index.service.IIndexService;
import com.stranger.index.web.vo.UserVO;

/**
 * @作者 stranger.lin
 *
 * @时间 2012-4-29
 */
public class IndexService implements IIndexService {
	
	private IndexDAO indexDAO;
	
	
	
	/**
	 * 验证登录
	 * @param vo
	 * */
	public TeachersBean  checkLogin(UserVO vo) throws Exception{

		
			TeachersBean bean=new TeachersBean();
		    BeanUtils.copyProperty(vo, bean);
		    bean=(TeachersBean)indexDAO.loadUser(bean);
			
		
		
		return bean;
	}
	
	/**
	 * 查询老师列表
	 * @throws 对象拷贝错误
	 * */
	public List<UserVO> findTeachersByWhere(UserVO vo)throws Exception{
		List<UserVO> list=new ArrayList<UserVO>();

			TeachersBean bean=new TeachersBean();
		    BeanUtils.copyProperty(vo, bean);
		    List<TeachersBean> beans=indexDAO.findListByAnyWhere(bean);
		    for (TeachersBean teacher : beans) {
		    	vo=new UserVO();
				BeanUtils.copyProperty(teacher, vo);
				list.add(vo);
			}
		
		
	    return list;
	}
	/**
	 * 添加教师
	 * @param vo 用户vo
	 * @throws  
	 *
	 * */
	public void insert(UserVO vo) throws Exception{
		TeachersBean bean=new TeachersBean();
		
	    BeanUtils.copyProperty(vo, bean);
	    bean.setId(UUID.randomUUID().toString());
	    indexDAO.insert(bean);
	}

	public IndexDAO getIndexDAO() {
		return indexDAO;
	}

	public void setIndexDAO(IndexDAO indexDAO) {
		this.indexDAO = indexDAO;
	}
	
	
	

}
